package com.ocp.socket.server.service;

import com.alibaba.fastjson.JSONObject;
import com.example.app.base.ResultStatus;
import com.ocp.socket.busi.warnMsg.mapper.BaseWarnMsgMapper;
import com.ocp.socket.common.Constants;
import com.ocp.socket.common.bean.UserInfo;
import com.ocp.socket.common.enums.ResultStatusEnum;
import com.ocp.socket.server.vo.MessageVo;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: zhangzh
 * @Date: 2019/3/3 07:01
 * @Description: APP报文处理
 * @Version: 1.0.0
 */
@Service("appService")
public class AppService {

    private final Logger logger = (Logger) LoggerFactory.getLogger(getClass());

    @Autowired
    BaseWarnMsgMapper baseWarnMsgMapper;



    /******
     * 保存App0002信息到数据库
     * @param messageVo
     * @return
     */
    public ResultStatus saveApp0002Data(MessageVo messageVo, IoSession session){
        //获取设备信息
        UserInfo userInfo = (UserInfo) session.getAttribute(Constants.ATTRIBUTE_KEY_AUTH);
        JSONObject obj = JSONObject.parseObject(messageVo.getJsonStr());//转换成json对象
        String id = obj.get("id").toString();//通过方法可以获取其中元素

        int n = baseWarnMsgMapper.updateOperUserById(id,userInfo.getUserId());
        if(n>0){
            return new ResultStatus(ResultStatusEnum.COMMON_SUCCESS,id);
        }else{
            return new ResultStatus(ResultStatusEnum.COMMON_FAIL,id);
        }
    }

}
